package convert.types;

import com.aspose.words.Document;
import com.aspose.words.FontSettings;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import convert.AbstractToPdf;

import java.io.InputStream;
import java.io.OutputStream;

/**
 * Word转PDF
 * <br>
 * Created by Hong 2024/7/4
 **/
public class WordToPdf extends AbstractToPdf {

    private final Document document;

    public WordToPdf(InputStream inputStream) throws Exception {
        this.document = new Document(inputStream);
    }

    @Override
    public void init() throws Exception {
        License license = new License();
        license.setLicense(getLicense());
    }

    @Override
    protected void fontSettings() {
        if (System.getProperty("os.name").contains("linux")) {
            FontSettings fontSettings = FontSettings.getDefaultInstance();
            fontSettings.setFontsFolder("/usr/share/fonts/chinese", true);
        }
    }

    @Override
    public void toPdf(OutputStream outputStream) throws Exception {
        document.save(outputStream, SaveFormat.PDF);
    }

    @Override
    public void close() {

    }
}
